﻿namespace UnityEditor
{
    using System;
    using UnityEngine;

    internal class ScaleTool
    {
        public static void OnGUI()
        {
            if ((Selection.activeTransform != null) && !Tools.s_Hidden)
            {
                Undo.SetSnapshotTarget(Selection.transforms, "Scale " + ((Selection.transforms.Length != 1) ? string.Empty : Selection.activeGameObject.name));
                Vector3 localScale = Selection.activeTransform.localScale;
                Vector3 vector2 = Handles.ScaleHandle(localScale, Tools.handlePosition, Tools.handleLocalRotation, HandleUtility.GetHandleSize(Tools.handlePosition));
                if (GUI.changed)
                {
                    Vector3 vector3;
                    vector3.x = (localScale.x == 0f) ? 1f : (vector2.x / localScale.x);
                    vector3.y = (localScale.y == 0f) ? 1f : (vector2.y / localScale.y);
                    vector3.z = (localScale.z == 0f) ? 1f : (vector2.z / localScale.z);
                    foreach (Transform transform in Selection.transforms)
                    {
                        Vector3 a = transform.localScale;
                        Vector3 vector5 = Vector3.Scale(a, vector3);
                        if ((((vector5.x != 0f) || (a.x == 0f)) && ((vector5.y != 0f) || (a.y == 0f))) && ((vector5.z != 0f) || (a.z == 0f)))
                        {
                            transform.localScale = vector5;
                        }
                    }
                }
            }
        }
    }
}

